package gui;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.List;
import midlet.MidletCielsa;
import util.CommandBuilder;

/**
 *
 * @author dcastaneda
 */
public class LstMenu extends List implements CommandListener{

    private MidletCielsa midlet;    
    
    private static final String[] MENU_ITEMS = {"Sincronizacion", "Visitas Programadas", "Reporte de Visitas", "Cerrar Sesión"};

    private Command cmdExit;
    private Command cmdSelect;
    private boolean sincronizado = false;

    public LstMenu(MidletCielsa midlet) {
        super("Menu", List.IMPLICIT, MENU_ITEMS, null);
        //changeFontItemSincronizar();
        this.midlet = midlet;        
        cmdExit = CommandBuilder.getExit();
        cmdSelect = CommandBuilder.getSelect();
        addCommand(cmdExit);
        addCommand(cmdSelect);
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdExit) {
            midlet.shutdown(false);
        } else if (c == cmdSelect) {            
            switch (getSelectedIndex()) {
                case 0:
                    FrmSincronizando fs = new FrmSincronizando(midlet, this);
                    midlet.setDisplay(fs);
                    break;
                case 1:
                    FrmVisitasProgramadas fvp = new FrmVisitasProgramadas(midlet, this);
                    midlet.setDisplay(fvp);
                    break;
                case 2:
                    FrmReporteVisitasDia frvd = new FrmReporteVisitasDia(midlet, this);
                    midlet.setDisplay(frvd);
                    break;
                case 3:
                    FrmConfirmacionSalida fcs = new FrmConfirmacionSalida(midlet, this);
                    midlet.setDisplay(fcs);
                    break;
            }
        }
    }

    private void changeFontItemSincronizar() {
        if (sincronizado) {
            setFont(0,getFont(1));
        } else {
            setFont(0, Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
        }
    }

    public void setSincronizado(boolean sincronizado) {
        this.sincronizado = sincronizado;
        changeFontItemSincronizar();
    }

}
